<!-- 视频列表 -->
<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="display: flex;justify-content: space-between;height: 52px;">
			<div>
				<p class="text">视频审核管理列表</p>
			</div>
			<el-form :inline="true" style="padding-right: 20px;margin-top: -5px;">
				<el-form-item>
					<el-dropdown size="small" placement="bottom" trigger="click" @command="batchView" style="margin-left: 10px;">
					    <el-button type="primary" size="small" class="search-btn">
							查询
							<i class="el-icon-arrow-down el-icon--right"></i>
					    </el-button>
					    <el-dropdown-menu slot="dropdown">
						    <el-dropdown-item command="ship_View" style='width: 90px;margin-bottom: 5px;'>
							   <el-button type="primary" size="small" icon="el-icon-view">待审核</el-button>
							</el-dropdown-item>
							<el-dropdown-item command="rece_View" style='width: 90px;margin-bottom: 5px;'>
								<el-button type="primary" size="small" icon="el-icon-view">已通过</el-button>
							</el-dropdown-item>
							<el-dropdown-item command="cus_View">
								<el-button type="primary" size="small" icon="el-icon-view">自定义</el-button>
							</el-dropdown-item>
					    </el-dropdown-menu>
					</el-dropdown>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="VideoList" highlight-current-row v-loading="loading" @selection-change="selsChange" border :cell-style="cellStyle" :header-cell-style="rowClass" style="width: 100%;">
			<el-table-column type="selection" width="55">
			</el-table-column>
			<el-table-column prop="id" align="center" label="ID" width="80">
			</el-table-column>
			<el-table-column prop="name" align="center" label="用户名">
			</el-table-column>
			<el-table-column prop="phone" align="center" label="手机号">
			</el-table-column>
			<el-table-column prop="title" align="center" label="视频标题">
			</el-table-column>
			<el-table-column prop="description" align="center" label="视频描述">
			</el-table-column>
			<el-table-column prop="thumbnail" align="center" label="封面图地址">
				<template slot-scope="scope">
					<img :src="scope.row.thumbnail" alt="封面图" style="width:70px;height: 100px;">
				</template>
			</el-table-column>
			<el-table-column prop="url" align="center" label="视频地址">
				<template slot-scope="scope">
					<video v-bind:src="scope.row.url" controls="controls" style="width:70px;height: 100px;"></video>
				</template>
			</el-table-column>
			<el-table-column prop="publishTime" align="center" label="发布时间">
			</el-table-column>
			<el-table-column prop="auditing" align="center" label="审核状态" :formatter="formataud" width="100">
			</el-table-column>
			<el-table-column label="操作" align="center" fixed="right" width="200">
				<template slot-scope="scope">
					<el-button v-if="scope.row.auditing == '1'" type="info" size="small" disabled>审核通过</el-button>
					<el-button v-else size="small" type="success" icon="el-icon-s-check" @click="handleEdit(scope.$index, scope.row)">审核</el-button>
					<el-button size="small" type="danger" icon="el-icon-delete" @click="handledel(scope.$index, scope.row)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		<!--批量删除-->
		<el-col :span="24" class="toolbar">
			<el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">单个/批量删除</el-button>
			<el-pagination background layout="total,sizes,prev, pager, next,jumper" @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-size="10" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
		<!-- 自定义查询-->
		<el-dialog title="自定义查询" :visible.sync="cusdialog" width="35%" :before-close="handleClose">
			<el-form :model="cusForm" label-width="105px" ref="cusForm">
				<el-form-item label="手机号" prop="phone">
					<el-input v-model="cusForm.phone" auto-complete="off" placeholder="请输入手机号" style="width: 220px;"></el-input>
				</el-form-item>
				<el-form-item label="标题" prop="title">
					<el-input v-model="cusForm.title" auto-complete="off" placeholder="请输入标题" style="width: 220px;"></el-input>
				</el-form-item>
				<el-form-item label="查询状态选择" prop="status">
					<el-radio-group v-model="cusForm.status">
						<el-radio class="radio" :label="0">待审核</el-radio>
						<el-radio class="radio" :label="1">已通过</el-radio>
					</el-radio-group>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="cusdialog = false">取 消</el-button>
				<el-button type="primary"  @click.native="cusSubmit" >查询</el-button>
			</span>
		</el-dialog>
	</section>
</template>
<script>
	import util from '../../../common/js/util'
	import {
		getVideoList,
		editVideo,
		delVideo,
		Refreshtoken
	} from '../../../api/api';
	export default {
		data() {
			return {
				loading: false,
				filters: {
					name:'',
					id:''
				},
				select: '',
				vid:'',
				VideoList: [],
				UserDetail:{},
				sels: [],//列表选中列81560
				total: 0,
				page: 1,
				size:10,
				aud:0,//-1:全部 0-待审 1-审核通过
				timer: null,
				cusdialog:false,
				cusForm:{
					phone:'',
					title:'',
					status:-1
				}
			}
		},
		mounted() {
			this.getUsers(0);
			this.queryInfo();
			this.timer = setInterval(() => {
			   setTimeout(this.queryInfo, 0)
		    }, 600000)
		},
		methods: {
			// 设置定时器
			queryInfo() {
				var Token = sessionStorage.getItem('Token');
				var timestamp=new Date().getTime();
				let para = {token: Token,timestamp: timestamp};
				Refreshtoken(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.loading = false;
					}
				});
			},
			// 转换性别状态
			formataud: function (row, column) {
				return row.auditing == 1 ? '通过' : row.auditing == 0 ? '待审' : '未知';
			},
			selsChange: function (sels) {this.sels = sels;},
			cellStyle({row, column}){return 'text-align:center';},
			rowClass({row, column}){return 'text-align:center';},
			changePriceValue(val){this.vid = val;},
			handleClose(done) {
				this.$confirm('确认关闭？')
					.then(_ => {
						done();
					})
					.catch(_ => {});
			},
			handleSizeChange(val) {
				if (this.fies == 0) {
					var a = this.fies
				} else if(this.fies == 1){
					var a = this.fies
				} else{
					var a = this.aud
				}
				this.size = val;
				this.getUsers(a);
			},
			handleCurrentChange(currentPage) {
				
				if (this.fies == 0) {
					var a = this.fies
				} else if(this.fies == 1){
					var a = this.fies
				} else{
					var a = this.aud
				}
				this.page = currentPage;
				this.getUsers(a);
			},
			// 自定义查询
			batchView(command){
				switch (command) {
				  case "ship_View":
					this.shipView(0);
					this.fies = 0;
					break;
				  case "rece_View":
					this.receView(1);
					this.fies = 1;
					break;
				  case "cus_View":
				  this.cusdialog = true;
				  break;
				  
				}
			},
			shipView(ind) {this.getUsers(ind)},
			receView(ind) {this.getUsers(ind)},
			//根据状态查询列表
			getUsers: function(aud) {
				var Token = sessionStorage.getItem('Token');
				var timestamp=new Date().getTime();
				var para = { token: Token, curpage:this.page, pagesize:this.size, auditing:aud, timestamp: timestamp};
				this.loading = true;
				getVideoList(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.total = res.data.total;
						this.VideoList = res.data.list;
						this.loading = false;
					}
				});
			},
			cusSubmit(){
				if (this.cusForm.status == '-1') {
					this.$notify({ title: '警告', message: '查询状态状态为必选项', type: 'warning' });
				}else{
					this.$refs.cusForm.validate((valid) => {
						if (valid) {
							this.$confirm('确认查询吗？', '提示', {}).then(() => {
								this.cusdialog = true;
								var Token = sessionStorage.getItem('Token');
								var timestamp = new Date().getTime();
								if (this.cusForm.phone != '') {
									var para = { token: Token, curpage:this.page, pagesize:this.size, auditing:this.cusForm.status, timestamp: timestamp,phone:this.cusForm.phone};
								}else if(this.cusForm.title != ''){
									var para = { token: Token, curpage:this.page, pagesize:this.size, auditing:this.cusForm.status, timestamp: timestamp,title:this.cusForm.title};
								}
								getVideoList(para).then((res) => {
									var res = res.data;
									if (res.code != 0) {
										this.$message({
											message: res.message,
											type: 'error'
										});
									} else {
										this.$message({
											message: '提交成功',
											type: 'success'
										});
										this.$refs['cusForm'].resetFields();
										this.cusdialog = false;
										this.total = res.data.total;
										this.VideoList = res.data.list;
										this.loading = false;
									}
								});
							});
						}
					});
				}
			},
			//通过审核
			handleEdit(index,row){
				this.$confirm('确认视频通过审核吗？', '提示', {}).then(() => {
					var Token = sessionStorage.getItem('Token');
					var timestamp=new Date().getTime();
					let para = {
						token: Token,
						id:row.id,
						timestamp: timestamp
					};
					this.loading = true;
					editVideo(para).then((res) => {
						var res = res.data;
						if (res.code != 0) {
							this.$message({
								message: res.message,
								type: 'error'
							});
						} else {
							this.$message({
								type: 'success',
								message: '视频审核通过！！！'
							});
							this.loading = false;
							this.getUsers();
						}
					});
				})
			},
			//单个/批量删除
			handledel:function(index,row){
				this.$confirm('确认删除选中记录吗？', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					var Token = sessionStorage.getItem('Token');
					var timestamp=new Date().getTime();
					let para = {token: Token, timestamp:timestamp, ids: row.id };
					delVideo(para).then((res) => {
						var res = res.data;
						if (res.code != 0) {
							this.$message({
								message: res.message,
								type: 'error'
							});
						} else {
							this.listLoading = false;
							this.$message({
								message: '删除成功',
								type: 'success'
							});
							this.getUsers();
						}
					});
				}).catch(() => {
							
				});
			},
			batchRemove: function () {
				var ids = this.sels.map(item => item.id).toString();
				this.$confirm('确认删除选中记录吗？', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					var Token = sessionStorage.getItem('Token');
					var timestamp=new Date().getTime();
					let para = {token: Token, timestamp:timestamp, ids: ids };
					delVideo(para).then((res) => {
						this.listLoading = false;
						//NProgress.done();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
						this.getUsers();
					});
				}).catch(() => {
			
				});
			}
		},
		
		beforeDestroy() {
		  clearInterval(this.timer);        
		  this.timer = null;
		}
	};
</script>

<style scoped> 
  .text{
  	font-family: "arial, helvetica, sans-serif";
  	font-size: 14px;
  	color: #333;
  	margin-top: 8px;
  	margin-left: 10px;
  	font-weight: 600;
  }
</style>
